package com.hmall.order.config;

import com.hmall.order.constant.MqConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DelayExchangeConfig {

    @Bean
    public DirectExchange delayExchange(){
        DirectExchange exchange = ExchangeBuilder.directExchange(MqConstant.ORDER_EXCHANGE).delayed().build();
        return exchange;
    }
    @Bean
    public Queue delayQueue(){
        Queue queue = QueueBuilder.durable(MqConstant.DELAY_QUEUE).build();
        return queue;
    }
    @Bean
    public Binding delayMsgBinding(){
        Binding binding = BindingBuilder.bind(delayQueue()).to(delayExchange()).with(MqConstant.DELAY_KEY);
        return binding;
    }
}